<?php
/**
 * Created by PhpStorm.
 * User: linyh
 * Date: 2017/11/25 0025 10:13
 */
?>
<link href="/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet" />
<section class="content-header">
    <h1>
        新闻发布
    </h1>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- general form elements -->
            <div class="box box-default">
                <!-- /.box-header -->
                <!-- form start -->
                <form id="form" role="form" class="form-horizontal">
                    <input type="hidden" value="1" name="type">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="input1" class="col-sm-2 control-label">新闻标题</label>
                            <div class="col-sm-9">
                            <input id="input1" class="form-control" type="text" value="" name="title">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input3" class="col-sm-2 control-label">新闻内容</label>
                            <div class="col-sm-8">
                            <script type="text/plain" name="content" id="myEditor" style="width:800px;height:240px;">
                                <p>这里写入新闻内容</p>
                            </script>
                            <!--</script>-->
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->

                    <div class="box-footer text-center">
                        <button type="submit" class="btn btn-success">发布</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

<script type="text/javascript" charset="utf-8" src="/ueditor/third-party/template.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/umeditor.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"></script>


<script>
var um = UM.getEditor('myEditor');
$('#form').submit(function(e) {
    e.preventDefault();
    var str = $('#form').serialize();
    console.log(str);

    $.ajax('/api/news/create', {
        type: 'POST',
        data: str,
        dataType: 'json',
        headers: {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
    }).then(function(ret) {
        if(ret.state ==0) {
            alert('保存成功');
            location.href = '/news/index';
        } else {
            alert(ret.message);
        }
    });
});

</script>